package com.ny.demo525.impl;

import com.ny.connect.SqlConnection;
import com.ny.demo525.ManagerDao;
import com.ny.entity.Manager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ManagerDaoImpl implements ManagerDao {
    Connection cont = SqlConnection.getCon();

    public ManagerDaoImpl() throws SQLException, ClassNotFoundException {
    }

    @Override
    public Manager log(String name, String pwd) throws SQLException {
        String sql = "select * from managers where name = ? and password = ?";
        PreparedStatement pst = cont.prepareStatement(sql);
        pst.setString(1,name);
        pst.setString(2,pwd);
        ResultSet rs = pst.executeQuery();
        if (rs.next()){
            Manager man = new Manager();
            man.setName(rs.getString("name"));
            man.setManager_pwd(rs.getString("password"));
            man.setManager_phone(rs.getString("phone"));
            return man;
        }else
            return null;
    }
}